﻿using System;
using TeamRobin.BattleCity.Core.CommonTypes;

namespace TeamRobin.BattleCity.Core.Utils
{
	internal class ConsoleUtil
	{
		static public int offset = 2;
		private static readonly object _locker = new object();

		public const char Empty = ' ';
		public static void Clear(Point point, string symbols)
		{
			Write(point, new string(Empty, symbols.Length));
		}

		public static void Write(Point point, char symbol, ConsoleColor color = ConsoleColor.Gray)
		{
			Write(point.X, point.Y, symbol.ToString(), color);
		}

		public static void Write(Point point, string symbols, ConsoleColor color = ConsoleColor.Gray)
		{
			Write(point.X, point.Y, symbols, color);
		}

		public static void Write(int x, int y, char symbol, ConsoleColor color = ConsoleColor.Gray)
		{
			Write(x, y, symbol.ToString(), color);
		}

		public static void Write(int x, int y, string symbols, ConsoleColor color = ConsoleColor.Gray)
		{
			Write(x, y, symbols, color: color, backgroundColor: ConsoleColor.Black);
		}

		public static void Write(int x, int y, string symbols,
			ConsoleColor color,
			ConsoleColor backgroundColor)
		{
			lock (_locker)
			{
				Console.ForegroundColor = color;
				Console.BackgroundColor = backgroundColor;
				Console.SetCursorPosition(x + offset, y + offset);
				Console.Write(symbols);
			}
		}
	}
}